package com.xlh.controller.conclude;


import com.xlh.common.Result;
import com.xlh.dto.conclude.*;
import com.xlh.enums.conclude.LikedSysFunkEnum;
import com.xlh.param.check.CheckClassParam;
import com.xlh.service.conclude.ConcludeCheckService;
import com.xlh.service.conclude.ConcludeService;
import com.xlh.vo.conclude.CheckListInfoVO;
import com.xlh.vo.conclude.ConcludeListInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 工程认证 - 考核项
 * <p>
 * chufangzheng
 */
@Api(tags = "ConcludeCheckController", description = "工程认证 - 考核项")
@RestController
@RequestMapping("/conclude/check")
public class ConcludeCheckController {

    @Autowired
    private ConcludeCheckService concludeCheckService;

    @ApiOperation("考核项列表展示")
    @GetMapping("/list")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<CheckListInfoVO>> list(@RequestParam Long concludeId) {
        List<CheckListInfoVO> list = concludeCheckService.list(concludeId);
        return Result.success(list);
    }

    @ApiOperation("考核项添加")
    @PostMapping("/add")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result add(@Valid @RequestBody ConcludeCheckAddDTO dto) {
        Long checkId = concludeCheckService.add(dto);
        return Result.success(checkId);
    }

    @ApiOperation("考核项修改")
    @PostMapping("/update")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result update(@Valid @RequestBody ConcludeCheckAddDTO dto) {

        Long checkId = concludeCheckService.update(dto);
        return Result.success(checkId);
    }

    @ApiOperation("考核项详情")
    @GetMapping("/detail")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result detail( @RequestParam Long checkId) {

        ConcludeCheckDetailDTO dto = concludeCheckService.detail(checkId);
        return Result.success(dto);
    }


    @ApiOperation("考核项删除")
    @DeleteMapping("/delete")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result delete(@Valid @RequestBody ConcludeParamDTO dto) {
        concludeCheckService.delete(dto);
        return Result.success();
    }


    @ApiOperation("考核项权重值设置")
    @PostMapping("/setweight")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result setweight(@RequestBody @Valid List<ConcludeCheckWeightDTO> dtos) {
        concludeCheckService.setWeight(dtos);
        return Result.success();
    }

    @ApiOperation("关联系统信息")
    @GetMapping("/findLinkSysInfo")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result findLinkSysInfo(){
        List<Map<String, Object>> LikedSysFunkEnums = concludeCheckService.findLinkSysInfo();
        return Result.success(LikedSysFunkEnums);
    }



}
